package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.AdminDAO;
import guda.house.dal.dataobject.AdminDO;
import guda.grape.autogen.common.page.BaseQuery;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AdminDAOImpl extends BaseDAO implements AdminDAO {

    @Override
	public Long insert(AdminDO admin) {
	      try {
                return (Long) getSqlMapperW().insert("admin.insert",admin);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public AdminDO getAdminById(Long adminId) {
	    return (AdminDO)getSqlMapClientTemplate().queryForObject("admin.getAdminById", adminId);
	}

    @Override
	public boolean delAdminById(Long adminId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("admin.delAdminById",adminId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<AdminDO> getAdminByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("admin.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long adminId) {
	    try {
            getSqlMapperW().update("admin.cleanAutoIncrement",adminId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<AdminDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("admin.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("admin.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(AdminDO admin) {
        try {
            getSqlMapperW().update("admin.updateByIdSelective",admin);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public AdminDO selectByUser(String username, String password) {
        Map m = new HashMap();
        m.put("loginName",username);
        m.put("loginPassword",password);
        return (AdminDO)getSqlMapClientTemplate().queryForObject("admin.selectByUser", m);
    }

}

